<template>
	<div class="centerleft">
		<ul class="leftlist">
			<li v-if="isShowList(item)" :class="{'active':isActive(item)}" class="item my-flex-center" @click="changeRouter(item.router,index)" v-for="(item,index) in menus">
				{{item.name}}
			</li>
		</ul>
	</div>
</template>

<script>
	export default {
		props: {
			currrentId: {
				type: Number,
				default: 0
			},
		},
		inject: ['reload', 'hasPermission'],
		data() {
			return {
				menus: [{
						name: '个人中心',
						id: 0,
						router: '/center/userCenter/index',
						show: true
					},
					{
						name: '我的资料',
						id: 1,
						router: '/address',
						show: true
					},
					{
						name: '密码修改',
						id: 2,
						router: '/userinfo',
						show: true
					},
					{
						name: '我的评论',
						id: 3,
						router: '/marks',
						show: true
					},
					{
						name: '我的货源',
						id: 4,
						router: '/releasemark',
						show: true
					},
					{
						name: '收货地址',
						id: 5,
						router: '/center/userCenter/goodAddress',
						show: false
					},
					{
						name: '消息通知',
						id: 6,
						router: '/collect',
						show: true
					},
					{
						name: '订单中心',
						id: 7,
						router: '/footmark',
						show: true
					},
					{
						name: '我的订单',
						id: 8,
						router: '/center/userCenter/myOrder',
						show: false
					},
					{
						name: '竞价管理',
						id: 9,
						router: '/childcount',
						show: false
					},
					{
						name: '资产中心',
						id: 10,
						router: '/update',
						show: true
					},
					{
						name: '我的账户',
						id: 11,
						router: '/update',
						show: true
					},
					{
						name: '支付密码设置',
						id: 12,
						router: '/update',
						show: true
					}, {
						name: '我的建议',
						id: 13,
						router: '/update',
						show: true
					}
				],
				currrentMenu: 2,
				listShow: 1
			}
		},
		computed: {
			onRoutes() {
				console.log(this.$route)
				return this.$route.path;
			},

		},

		mounted() {
			//			this.modifyCurrentIndex();
			//			this.checkPermission();
			console.log(this.$store.state.userInfo)
		},
		methods: {
			isShowList(item) {
				let arr1 = [0, 1, 3, 6, 7, 10]; //个人买家账号显示页面
				let arr2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; // 企业主账号
				let arr3 = [0, 1, 3, 4, 6, 7]; //子账号
				let userInfo = this.$store.state.userInfo;
				if(userInfo && userInfo.type === 0) { //个人买家
					if(arr1.indexOf(item.id) > -1) {
						return true;
					} else {
						return false;
					}
				}
				if(userInfo && userInfo.type == 1 && userInfo.isMasterAccount) {
					if(arr2.indexOf(item.id) > -1) {
						return true;
					} else {
						return false;
					}
				}
				if(userInfo && userInfo.type == 1 && !userInfo.isMasterAccount) {
					if(arr3.indexOf(item.id) > -1) {
						if(item.id == 4) { //发标
							if(userInfo.permissionIds.indexOf(5) > -1) {
								return true;
							} else {
								return false;
							}
						}
						return true;
					} else {
						return false;
					}
				}
				return true;
			},
			isActive(item) {
				if(this.onRoutes.indexOf(item.router) > -1) {

					return true;
				} else {
					return false
				}
			},
			modifyCurrentIndex() {
				if(this.$store.state.userInfo.type == '0') {
					this.currrentMenu = 10;
				} else {
					this.currrentMenu = 2;
				}
			},
			changeRouter(url, index) {
				this.currrentMenu = index;
				//				sessionStorage.setItem('currrentMenu', this.currrentMenu);
				this.$nextTick(() => {
					this.$router.push(url);
				})
			},

			checkPermission() { //1企业买家，0：个人买家
				var list = this.menus;
				list.forEach(item => {
					switch(item.id) {
						case 2: //个人资料：个人买家不显示个人资料，到升级企业买家
							if(this.$store.state.userInfo.type == '0') {
								item.show = false;
							} else {
								item.show = true;
							}
							break;
						case 4: //发标
							if(this.$store.state.userInfo.isMasterAccount && this.$store.state.userInfo.type == '1') {
								item.show = true;
							} else {
								item.show = false;
							}
							break;
						case 5: //钱包
							if(this.$store.state.userInfo.isMasterAccount && this.$store.state.userInfo.type == '1') {
								item.show = true;
							} else {
								item.show = false;
							}
							break;
						case 8: //银行卡
							if(this.$store.state.userInfo.isMasterAccount && this.$store.state.userInfo.type == '1') {
								item.show = true;
							} else {
								item.show = false;
							}
							break;
						case 9: //子账号
							if(this.$store.state.userInfo.isMasterAccount == true && this.hasPermission(1) && this.$store.state.userInfo.type == '1') {
								item.show = true;
							} else {
								item.show = false;
							}
							break;
						case 10: //升级
							if(!this.$store.state.userInfo.isMasterAccount && this.$store.state.userInfo.type == '0') {
								item.show = true;
							} else {
								item.show = false;
							}
							break;
					}
				})
				this.menus = list;
			}
		}
	}
</script>

<style lang="less">
	@import '../../less/base/base.less';
	.centerleft {
		margin-right: 20px;
		position: fixed;
		z-index: 1;
		overflow-x: hidden;
		.leftlist {
			border: 1px solid #ebebeb;
			.item {
				background: #fff;
				font-size: 16px;
				width: 140px;
				height: 50px;
				border-bottom: 1px solid #ebebeb;
				cursor: pointer;
				border-left: 6px solid transparent;
				&:nth-last-of-type(1) {
					border-bottom: none;
				}
				&.active {
					border-left: 6px solid @base-color;
					background-color: #f7f7f7;
					color: @base-color;
				}
			}
		}
	}
</style>